
import sys
import numpy as np
import open3d as o3d
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
from PyQt5.QtCore import QTimer

class Open3DExample(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update)
        self.timer.start(16) # 60 frames per second
        self.viewer = o3d.visualization.Visualizer()
        self.viewer.create_window()
        self.loadPointCloud()

    def initUI(self):
        self.setWindowTitle('Open3D in PyQt5')
        self.setGeometry(100, 100, 800, 600)
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

    def loadPointCloud(self):
        pcd = o3d.geometry.PointCloud()
        pcd.points = o3d.utility.Vector3dVector(np.random.rand(1000, 3))
        pcd.paint_uniform_color([1, 0, 0]) # Paint the points with red color
        self.viewer.add_geometry(pcd)

    def update(self):
    # Update the point cloud here if needed
        pass

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Open3DExample()
    window.show()
    sys.exit(app.exec_())